<template>
	<view>
		<view class="p-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white flex space-between">
				<view>
					<view class="font-bold">{{info.username}}</view>
					<view class="font-24 mt-20">工作{{calculateAge(info.workTime)}}年 · {{calculateAge(info.birthday)}}岁</view>
				</view>
				<image src="../../static/images/avatar.png" mode=""
					style="width: 100rpx;height: 100rpx;border-radius: 50%;"></image>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="font-26 font-bold">个人优势</view>
				<view class="mt-20 font-24">{{info.selfIntroduction}}</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white flex space-between">
				<view class="font-26 font-bold">求职状态</view>
				<view class="font-24 font-grey">{{getStatus(info.applyStatus)}}</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="font-26 font-bold">求职意向</view>
				<view class="mt-20" v-for="(item, index) in intentionLists" :key="index">
					<view class="flex space-between flex-align-end">
						<view class="font-26">{{item.expectPosition}}</view>
						<view class="flex">
							<view class="font-20">{{item.expectPayLow}}-{{item.expectPayHigh}}</view>
						</view>
					</view>
					<view class="font-24 font-grey mt-10">{{item.expectCity}} · {{item.expectProfession}}</view>
				</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="font-26 font-bold">工作经历</view>
				<view class="mt-20" v-for="(item, index) in workLists" :key="index">
					<view class="flex space-between flex-align-end">
						<view class="font-26">{{item.companyName}}</view>
						<view class="flex">
							<view class="font-20 font-grey">{{item.startTime}}-{{item.endTime}}</view>
						</view>
					</view>
					<view class="font-24 font-grey mt-10">{{item.profession}} · {{item.position}}</view>
					<view class="font-22 font-grey mt-20">{{item.workInfo}}</view>
				</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="font-26 font-bold">项目经历</view>
				<view class="mt-20" v-for="(item, index) in projectLists" :key="index">
					<view class="flex space-between flex-align-end">
						<view class="font-26">{{item.name}}</view>
						<view class="flex">
							<view class="font-20 font-grey">{{item.startTime}}-{{item.endTime}}</view>
						</view>
					</view>
					<view class="font-24 font-grey mt-10">{{item.role}}</view>
					<view class="font-22 font-grey mt-20">{{item.info}}</view>
				</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="font-26 font-bold">教育经历</view>
				<view class="mt-20" v-for="(item, index) in educationLists" :key="index">
					<view class="flex space-between flex-align-end">
						<view class="font-26">{{item.name}}</view>
						<view class="flex">
							<view class="font-20 font-grey">{{item.startTime}}-{{item.endTime}}</view>
						</view>
					</view>
					<view class="font-24 font-grey mt-10">{{item.education}}</view>
					<view class="font-22 font-grey mt-20">{{item.info}}</view>
				</view>
			</view>
		</view>

		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="font-26 font-bold">资格证书</view>
				<view class="flex flex-wrap items-center">
					<view class="mt-20 mr-20" v-for="(item, index) in credentialLists" :key="index">
						<image :src="item.credential" mode="" style="width: 100rpx;height: 100rpx;">
						</image>
					</view>
				</view>
			</view>
		</view>

		<view class="bottom-view flex space-around">
			<view class="bottom-btn font-white bg-g" @click="submit">预约面试</view>
			<view class="bottom-btn font-white bg-blue" @click="telphone">拨打电话</view>
		</view>
	</view>
</template>

<script>
	import { queryById } from '../../api/apply_user.js';
	import { list as workList } from '../../api/apply_work.js';
	import { list as projectList } from '../../api/apply_project.js';
	import { list as educationList } from '../../api/apply_education.js';
	import { list as intentionList } from '../../api/apply_intention.js';
	import { list as credentialList } from '../../api/apply_credential.js';
	import {
		add
	} from '../../api/message.js';
import { getInfo } from '../../api/hr_user.js';
	export default {
		data() {
			return {
				id: 0,
				info: {},
				workLists: {},
				projectLists: {},
				educationLists: {},
				intentionLists: {},
				credentialLists: {},
			};
		},
		onLoad(options) {
			this.id = options.id
			console.log(options)
			this.getDetail()
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: '河口人才招聘小程序',
				path: '/pages/lists/info'
			}
		},
		methods: {
			telphone() {
				uni.makePhoneCall({
					phoneNumber: this.info.mobile
				});
			},
			calculateAge(birthdate) {
				var today = new Date();
				var birthDate = new Date(birthdate);
				var age = today.getFullYear() - birthDate.getFullYear();
				var monthDiff = today.getMonth() - birthDate.getMonth();
			
				if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
					age--;
				}
			
				return age;
			},
			getDetail() {
				queryById({
					id: this.id
				}).then(res => {
					this.info = res.result
					this.getOther(this.info.id)
				})
			},
			getOther(id) {
				workList({
					id: id
				}).then(res => {
					this.workLists = res.result
				})
				projectList({
					id: id
				}).then(res => {
					this.projectLists = res.result
				})
				educationList({
					id: id
				}).then(res => {
					this.educationLists = res.result
				})
				intentionList({
					id: id
				}).then(res => {
					this.intentionLists = res.result
				})
				credentialList({
					id: id
				}).then(res => {
					this.credentialLists = res.result
				})
			},
			submit() {
				const _this = this
				this.$tips.showModal('是否提交打招呼消息？', () => {
					// _this.$tips.showConfirmModal('提交成功，请等待审核', () => {
					// })
					getInfo().then(red => {
						if (red.code === 200) {
							add({
								to_user: this.info.appuserId,
								type: 1,
								title: '招聘信息提示',
								message: '有公司对您的简历感兴趣，点击查看该公司信息',
								info: red.result.companyId
							}).then(res => {
								if (res.code === 200) {
									_this.$tips.showConfirmModal('提交成功，请耐心等待回复', () => {})
								} else {
									_this.$tips.showConfirmModal('提交失败，请重试', () => {})
								}
							})
						} else {
							_this.$tips.showConfirmModal('请先填写简历', () => {})
						}
					})
				})
			},
			getStatus(status) {
				switch (status) {
					case 1:
						return '离职-随时到岗'
					case 2:
						return '在职-月内到岗'
					case 3:
						return '在职-考虑机会'
					case 4:
						return '在职-暂不考虑	'
				}
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
		padding-bottom: 200rpx;
	}

	.bottom-view {
		width: 100vw;
		padding: 40rpx 0;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 99999;
		border-top: 1px solid #efefef;

		.bottom-btn {
			width: 45vw;
			margin: auto;
			text-align: center;
			border-radius: 50rpx;
			padding: 20rpx 0;
		}
	}
</style>